﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using inhame_3d.Objetos;

namespace inhame_3d.Objetos
{
    class GameObjectManager
    {
        private BoundingBox collisionBox;
        /// <summary>
        /// Esfera de Colisão do Objeto
        /// </summary>
        public BoundingBox CollisionBox { get { return this.collisionBox; } set { this.collisionBox = value; } }

        private BoundingSphere collisionSphere;
        /// <summary>
        /// Esfera de Colisão do Objeto
        /// </summary>
        public BoundingSphere CollisionSphere { get { return this.collisionSphere; } set { this.collisionSphere = value; } }

        private List<GameObject> generalList = new List<GameObject>();

        public List<GameObject> ObjectList = new List<GameObject>();
        public List<Item> ItensList = new List<Item>();
        public List<Player> PlayerList = new List<Player>();

        public GameObjectManager()
        {
            
        }

        public void Update(GameTime gameTime)
        {
            foreach (Player player in PlayerList)
            {
                if (!Colision.ObjectColision(player, ObjectList))
                {
                    player.Position = player.FuturePosition;
                }
                else
                {
                    player.Position = player.LastPosition;
                }
                player.Update(gameTime);
            }

            foreach (GameObject obj in ObjectList)
            {
                obj.Update(gameTime);
            }

            foreach (Item Item in ItensList)
            {
                Item.Update(gameTime);
            }
        }

        public void Draw(inhame_3d.Cameras.ThirdPersonCamera camera)
        {
            foreach (Player player in PlayerList)
            {
                player.DrawModel(camera);
            }

            foreach (GameObject obj in ObjectList)
            {
                obj.DrawModel(camera);
            }

            foreach (Item Item in ItensList)
            {
                Item.DrawModel(camera);
            }
        }
    }
}
